package com.yy.QSManage.api;

import com.yy.QSManage.common.Result;
import com.yy.QSManage.model.dto.ChangePasswordDto;
import com.yy.QSManage.model.dto.LoginDto;
import com.yy.QSManage.model.dto.LoginResultDto;
import com.yy.QSManage.model.entity.FaSysMember;
import com.yy.QSManage.service.FaSysMemberRoleService;
import com.yy.QSManage.service.FaSysMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/FaSysMemberApi")
@Api(tags = "用户管理")
public class FaSysMemberApi extends BaseApi<FaSysMember>{

    @Autowired
    FaSysMemberService memberService;

    @Autowired
    FaSysMemberRoleService memberRoleService;

    @ApiOperation("后台登录第一层校验")
    @ApiImplicitParam(name = "loginInfoDto",value = "登录对象",dataType = "LoginInfoDto",paramType = "body")
    @PostMapping(value = "/login")
    public Result<LoginResultDto> login(@RequestBody LoginDto loginInfoDto, HttpServletRequest request){
        LoginResultDto loginResultDto = memberService.login(loginInfoDto, request);
        return Result.success(loginResultDto);
    }

    @ApiOperation("退出登录")
    @GetMapping("/logout")
    public Result logout(HttpServletRequest request) {
        memberService.logout(request.getHeader("token"));
        return Result.success();
    }

    @ApiOperation("修改密码")
    @ApiImplicitParam(name = "changePasswordDto",value = "登录对象",dataType = "ChangePasswordDto",paramType = "body")
    @PostMapping(value = "/changePassword")
    public Result changePassword(@RequestBody ChangePasswordDto changePasswordDto){
        memberService.changePassword(changePasswordDto);
        return Result.success();
    }
}

